<template>
    <div>
        <h1>科室显示</h1>
        <div>
            科室名称 : <input type="text" v-model="queryinfo.departName">
            科室简介 : <input type="text" v-model="queryinfo.desc">
            创建时间 : <input type="date" v-model="queryinfo.createtime">
            <input type="button" value="查询" @click="getlist()">

        </div>
        <table class="table table-bordered">
            <tbody>
                <tr>
                    <td>科室id</td>
                    <td>科室名称</td>
                    <td>科室人数</td>
                    <td>科室介绍</td>
                    <td>创建时间</td>
                    <td>操作</td>
                </tr>
                <tr v-for="item in list">
                    <td>{{ item.departmentId }}</td>
                    <td>{{ item.departmentName }}</td>
                    <td>{{ item.departmentNumber }}</td>
                    <td>{{ item.departmentDesc }}</td>
                    <td>{{ item.createTime }}</td>
                    <td>
                        <input type="button" value="删除" @click="del(item.departmentId)">
                        <input type="button" value="修改" @click="Update(item.departmentId)">
                    </td>
                </tr>
            </tbody>
        </table>
        <input type="button" value="刷新" @click="regert">
    </div>
</template>

<script setup lang="ts">
import axios from 'axios';
import { ref, reactive, onMounted } from 'vue';
import moment from 'moment';
import { useRoute, useRouter } from 'vue-router';
const route = useRoute();
const router = useRouter();

onMounted(() => {
    getlist();
})

let list: any = ref([]);
let queryinfo: any = reactive({
    departName: "",
    desc: "",
    createtime: ""
})
const getlist = () => {
    axios({
        url: '/api/Ward/GetDepartments',
        method: 'get',
        params: queryinfo
    })
        .then(res => {
            list.value = res.data;
        })
        .catch(err => {

        })
}
const del = (id: any) => {
    if (confirm("你确定要删除吗")) {
        axios({
            url: '/api/Ward/DepartmentDelete',
            method: 'delete',
            params: { id: id },
        })
            .then(res => {
                if (res.data > 0) {
                    alert("删除成功");
                    getlist();
                    return;
                }
                else {
                    alert("删除失败");
                    return;
                }
            })
            .catch(err => {

            })
    }

}
const Update = (id: any) => {
    router.push({
        path: '/departmomentUpdate',
        query: { id: id },
    })
}
const regert = () => {
    queryinfo.departName = "",
        queryinfo.desc = "",
        queryinfo.createtime = "",
        getlist();

}
</script>


<style scoped></style>